import request from "@/utils/request"
import { HeadersContentType } from "@/utils/request"
/**
 * @description 获取当前登录用户信息
 * @returns
 */
export function getCurrentUserInfo(params) {
  return request({
    url: "/monster-im/user/userInfo",
    method: "get",
    headers: {
      "Content-Type": HeadersContentType.urlencoded
    },
    params
  })
}

export function getCurrentChatInfo(id) {
  return request({
    url: `/monster-im/user/${id}`,
    method: "get",
    headers: {
      "Content-Type": HeadersContentType.urlencoded
    }
  })
}

/**
 * 获取当前聊天信息
 * @param {string} id - 会话ID
 * @returns {Promise} - 返回一个Promise对象，用于处理异步请求
 */
export function getCurrentChat(id) {
  return request({
    url: `/monster-im/chat/${id}`,
    method: "get",
    headers: {
      "Content-Type": HeadersContentType.urlencoded
    }
  })
}

/**
 * @description 获取群组列表
 * @returns
 */
export function getContactGroupList(data) {
  return request({
    url: "/monster-im/group/list",
    method: "get",
    headers: {
      "Content-Type": HeadersContentType.json
    },
    data
  })
}

/**
 * @description 获取单条群组
 * @returns
 */
export function getSingleGrop(groupId) {
  return request({
    url: `/monster-im/contacts/group/${groupId}`,
    method: "get",
    headers: {
      "Content-Type": HeadersContentType.json
    }
  })
}

/**
 * @description 通过名称和警号获取人员
 * @returns
 */
export function getUserList(data) {
  return request({
    url: `/monster-im/user/list`,
    method: "post",
    headers: {
      "Content-Type": HeadersContentType.json
    },
    data
  })
}

/**
 * 创建群组
 * @param {*} data
 * @returns
 */
export function createGroup(data) {
  return request({
    url: `/monster-im/contacts/group`,
    method: "POST",
    idempotent: true,
    headers: {
      "Content-Type": HeadersContentType.json
    },
    data
  })
}

/**
 * 添加移除群成员
 * @param {*} data
 * @returns
 */
export function updateUserToGroup(data) {
  return request({
    url: `/monster-im/contacts/group/members`,
    method: "put",
    idempotent: true,
    headers: {
      "Content-Type": HeadersContentType.json
    },
    data
  })
}

export function updateSingleGroup(data) {
  return request({
    url: `/monster-im/contacts/group`,
    method: "put",
    headers: {
      "Content-Type": HeadersContentType.json
    },
    data
  })
}

/**
 *
 * @param {*} groupId 群组id
 * @returns
 */
export function deleteGroup(groupId) {
  // 发送一个delete请求，请求地址为/monster-im/contacts/group/${groupId}
  return request({
    url: `/monster-im/contacts/group/${groupId}`,
    method: "delete",
    headers: {
      // 设置请求头Content-Type为json
      "Content-Type": HeadersContentType.json
    }
  })
}

/**
 * 修改用户信息
 * @param {*} data
 * @returns
 */
export function updateUserInfo(data) {
  return request({
    url: `/monster-im/user`,
    method: "put",
    headers: {
      "Content-Type": HeadersContentType.json
    },
    data
  })
}

export function logout() {
  return request({
    // eslint-disable-next-line no-undef
    otherUrl: logoutUrl,
    method: "get",
    headers: {
      "Content-Type": HeadersContentType.json
    }
  })
}

/**
 * 搜索会话
 * @param {*} data
 * @returns
 */
export function searchRecentChat(data) {
  return request({
    url: `/monster-im/chat/list`,
    method: "post",
    headers: {
      "Content-Type": HeadersContentType.json
    },
    data
  })
}

export function searchContactAndGroup(params) {
  return request({
    url: `/monster-im/contacts/search`,
    method: "get",
    headers: {
      "Content-Type": HeadersContentType.json
    },
    params
  })
}

export function getFriendList(params) {
  return request({
    url: `/monster-im/friend/list`,
    method: "get",
    headers: {
      "Content-Type": HeadersContentType.json
    },
    params
  })
}
